<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h1>Vue-Router</h1>
      <nav>
        <router-link to="/">Go to Home</router-link> |
        <router-link to="/about">Go to About</router-link>
      </nav>
      <main>
        <router-view></router-view>
      </main>
    </div>

    <script src="../Vue.js"></script>
    <script src="../VueRouter.js"></script>

    <script>
      const { createApp } = Vue;
      const { createMemoryHistory, createRouter } = VueRouter;

      const HomeComponent = {
        template: `
          <div>这是首页</div>
        `,
      };

      const AboutComponent = {
        template: `
          <div>这是关于页</div>
        `,
      };

      const routes = [
        {
          url: "/",
          component: HomeComponent,
        },
        {
          url: "/about",
          component: AboutComponent,
        },
      ];

      const router = createRouter({
        history: createMemoryHistory(),
        routes,
      });

      createApp({
        data() {
          return {};
        },
      })
        .use(router)
        .mount("#app");
    </script>
  </body>
</html>
